package com.example.demo.config;

import com.example.demo.handler.ChatWebSocketHandler;
import com.example.demo.interceptor.AuthHandShakeInterceptor;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.*;


@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {

    @Resource
    private AuthHandShakeInterceptor authHandShakeInterceptor;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(new ChatWebSocketHandler(), "/ws/chat")
                .setAllowedOriginPatterns("*")
                .addInterceptors(authHandShakeInterceptor);
    }
}
